import { PageContainer } from '@ant-design/pro-layout';
import React, {useRef} from 'react';
import type { ProColumns } from '@ant-design/pro-table';
import {invoicedFormList} from '../../pages/StockIO/service';
import ProTable, { ActionType } from '@ant-design/pro-table';

export type PutOutProps = {
  admin:boolean;
  had:boolean;
};

const OutTicket: React.FC<PutOutProps> = (props)=>{
  const actionRef = useRef<ActionType>();

  //表头信息以及表值设置
  const columns: ProColumns[] = [
    {
      title:'客户代码',
      dataIndex: 'loginName',
      fixed:'left',
      hideInTable:props.admin?false:true,
      hideInSearch:props.admin?false:true,
    },
    {
      title:'客户名称',
      dataIndex: 'cnName',
      fixed:'left',
      hideInTable:props.admin?false:true,
      hideInSearch:props.admin?false:true,
    },
    {
      title:'出库单号',
      dataIndex: 'put_out_no',
      fixed:'left'
    },
    {
      title: '产品名称',
      dataIndex: 'product_name',
    },
    {
      title: '产品型号',
      dataIndex: 'product_standard',
    },
    {
      title: '单位',
      dataIndex: 'packing_unit',
      hideInSearch:true
    },
    {
      width:120,
      title: '批号',
      dataIndex: 'batch',
    },
    {
      width:120,
      title: '失效日期',
      dataIndex: 'validity',
      hideInSearch:true
    },
    {
      width:100,
      title: '出库数量',
      dataIndex: 'numbs',
      hideInSearch:true
    },
    {
      width:100,
      title: '已开票数量',
      dataIndex: 'invoicing',
      hideInSearch:true
    },
    {
      width:100,
      title: '未开票数量',
      dataIndex: 'invoicing',
      hideInSearch:true,
      renderText:(_,record)=>{
        return Number(record.numbs)-Number(record.invoicing)
      }
    },
    // {
    //   width:100,
    //   title: '总价(元)',
    //   valueType:'money',
    //   dataIndex: 'original_price',
    //   hideInSearch:true
    // }
  ];

  return (
    <PageContainer>
    <ProTable
      scroll={props.admin?{x:1500}:{}}
      headerTitle='未开票产品表'
      actionRef={actionRef}
      request={(params, sorter, filter) => {
        if(params.date){
          params.beginDate=params.date[0];
          params.endDate=params.date[1];
          params.date=undefined;
        }
        return invoicedFormList({...params,filter})
       }}
      columns={columns}
      rowKey={record => record.put_out_no + record.product_standard+record.batch}
      search={{
        span:6
      }}
      toolBarRender={false}
      toolbar={{settings:[]}}
      pagination={{
        pageSizeOptions:['20', '100', '500']
      }}
      />
  </PageContainer>
  );
}

export default OutTicket;